1. Technical Field
The present invention relates to a method and apparatus for producing a graphical image and in particular to a method and apparatus for shading a graphical image displayed within a data processing system. More specifically, the present invention provides a method and apparatus for shading polygons displayed in a data processing system minimizing creating undesirable artifacts.
2. Description of the Related Art
Computer graphics display systems, e.g., CAD/CAM graphics work stations, are widely utilized to generate and display images of objects for scientific, engineering, manufacturing, and other applications. These computer graphics systems offer a range of visual effects, including graphic images nearing photographic quality. Many applications may not require a picture-perfect quality, but they do require accurate three-dimensional drawings of objects with shading and multiple light sources. In computer graphics display systems, surfaces of an object are usually represented by a polygon mesh. A polygon mesh is a collection of vertices, edges, and polygons. A mesh of polygons can come from many sources such as, an application, tesselated NURBS surfaces, spheres, cones, etc. The vertices are connected by edges, while the polygons may be thought of as a sequence of edges or of vertices.
Polygonal representation of objects is an artifact of image generation in a computer graphics system and is usually of no interest to viewers. To present a visual of an object on a video display which is more realistic in appearance than the corresponding polygon mesh, various procedures have been developed for removing hidden surfaces and shading and adding texture to visible surfaces in computer graphics systems. The efficiency of operations involving shading is critical to the performance of a computer graphics system since such an operation usually is performed for one million or more pixels per image.
Gouraud shading, also called "intensity interpolation shading" or "color interpolation shading", is a commonly used shading method in real-time systems to eliminate intensity discontinuities. A detailed explanation of Gouraud shading may be found in a text authored by Foley, Van Dam, Feiner, and Hughes entitled Computer Graphics: Principles and Practice published by Addison-Wesley Publishing Company (2d ed. 1990). Gouraud shading may be applied to individual polygons in a polygon mesh by interpolating polygon vertex illumination values that take into account the surface being approximated. This shading process requires that the normal vector be known for each vertex of the polygonal mesh. Alternatively, if the vertex normals are not stored with the mesh and cannot be determined directly from the actual surface, they may be approximated by averaging the surface normals of all the polygonal facets sharing each vertex.
Next, vertex intensities may be found utilizing the vertex normals with any desired illumination model. Finally, each polygon is shaded by linear interpolation of vertex intensities along each edge and then between edges. This method is popular for real-time systems because it produces images of acceptable quality with only one addition per pixel per color-band, but the shading creates undesirable artifacts.
For example, one artifact is the spreading of a spectral highlight occurring at a vertex throughout much of a polygon. Additionally spectral highlights within a polygon are totally missed if they do not in part land on a vertex. Other disturbing characteristics associated with Gouraud shading include the fact that moving objects tend to "flatten out" at certain viewing angles, surfaces appear dull or chalky, and images show pronounced Mach bands, exaggerations of intensity change at discontinuities.
Phong shading, also known as "normal-vector interpolation shading", is a better approach to shading that eliminates "flattening out" and dull surfaces and reduces Mach bands by interpolating the surface normal vector N, rather than the intensity. Bold characters and ".fwdarw." are utilized to denote vectors. This approach involves interpolating normal vectors supplied at each vertex and applying a lighting equation at each point. More information on shading techniques such as Gouraud shading and Phong shading along with other principles of shading may be found in a text authored by Foley, Van Dam, Feiner, and Hughes entitled Computer Graphics: Principles and Practice published by Addison-Wesley Publishing Company (2d ed. 1990).
Referring now to FIG. 1, there is depicted a diagram illustrating the geometry involved in an illumination model. N is the vector normal to the surface of a displayed object 30, V is the view-point vector pointing towards viewer 32, L is the light source vector, and H is the "Halfway" vector or perfect specular vector reflection. .theta. is the angle of incidence and .beta. is the angle between H and N.
The following is a list of symbols and their definitions:
V is the vector pointing in the direction of the viewpoint. PA0 N is the outward surface normal vector. This vector is interpolated over the triangle given its value at the three vertices. PA0 H is the "halfway" vector or perfect specular-reflection vector. Like the normal vector, this vector is interpolated over the triangle. H=(L+V)/2. PA0 f.sub.att the attenuation of light from the position of the eye to the position on the surface (usually about 1). PA0 I.sub.a.lambda. is the ambient light intensity as a function of wavelength .lambda., which is commonly allowed to take on the red, green, and blue wavelengths. PA0 I.sub.p.lambda.j is the intensity of point light source j as a function of .lambda.. PA0 j is a summation variable (sum over all light sources). PA0 k.sub.ar is the ambient light reflection coefficient of the object. PA0 k.sub.sr is the specular reflection coefficient of the object. PA0 k.sub.dr is the diffuse reflection coefficient of the object. PA0 L is the vector to the light source from the object (interpolated over the triangle). PA0 O.sub.d.lambda. is the diffuse color of the object. PA0 O.sub.s.lambda. is the specular color of object. PA0 .beta. is the angle between vectors N and H (see FIG. 1). PA0 .theta. is the angle between vectors N and L. PA0 n is the specular highlight exponent. (usually=[1,128])
Note: ".lambda." implies three color components, red, green, and blue.